import os
import sys
import uuid
import asyncio

from app.core.local_file import LocalFile
from app.config.es import EsConfig
from app.retriever.es import MyElasticsearch
from app.retriever.milvus import MilvusVectorStore

from app.dao.ai import AiDao
from app.dao.file import FileDao
from app.schema.file import *
from app.utils.db import DbUtils

async def add_data(): # 获取全部的ai，修改ai的vector_name 并获取ai的所有的file 并添加到milvus中
    ai_list = AiDao().get_all_ai()
    for ai in ai_list[0:]:

        file_list = FileDao().read_by_ai_id(ai.id)
        for file in file_list:
            file_milvus = MilvusFileSchema(file_id=file.id,file_name=file.name,url=file.url)
            milvus = MilvusVectorStore(ai.vector_name)
            es_store=MyElasticsearch(ai.vector_name)
            local_file = LocalFile(file_milvus, milvus=milvus,es_store=es_store)
            await local_file.download_file() # 下载文件到本地
            await local_file.split_file_to_docs() # 切割文件,上传并删除本地文件



if __name__ == '__main__':
    asyncio.run(add_data())